define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'campus_mall_order_reviews/index' + location.search,
                    add_url: 'campus_mall_order_reviews/add',
                    edit_url: 'campus_mall_order_reviews/edit',
                    del_url: 'campus_mall_order_reviews/del',
                    multi_url: 'campus_mall_order_reviews/multi',
                    import_url: 'campus_mall_order_reviews/import',
                    table: 'campus_mall_order_reviews',
                }
            });

            var table = $("#table");
//https://720yun.com/t/11vkbwr777w?scene_id=91897481
            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: '', title: __('用户'),
                            formatter: function(row,data){
                                console.log(row,data)
                                let html = '<div data-sn="'+data.sn+'" data-id="'+data.id+'">'+data.user.username+'&nbsp;'+data.user.mobile+'</div>'
                                return html
                            }},
                        {field: 'campusmallgoods.name', title: __('Campusmallgoods.name'), operate: 'like'},
                        {field: 'campusmallgoods.image', title: __('Campusmallgoods.image'), formatter: Table.api.formatter.image, operate: false},
                        {field: 'levels', title: __('Levels'), searchList: {"1":__('Levels 1'),"2":__('Levels 2'),"3":__('Levels 3'),"4":__('Levels 4'),"5":__('Levels 5')}, formatter: Table.api.formatter.normal},
                        {field: 'images', title: __('Images'), formatter: Table.api.formatter.images, operate: false},
                        {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1')}, formatter: Table.api.formatter.toggle},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});